﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity = ChatForum.Business.Entity;
using System.Web.UI.HtmlControls;

namespace ChatForum.Client
{
    public partial class SiteLayout : System.Web.UI.MasterPage
    {
        internal static Entity.User CurrentUser
        {
            get
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                    return ServiceHelper.ServiceHelper.AccountService.GetUser(HttpContext.Current.User.Identity.Name);
                else
                    return null;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
			{
				HtmlAnchor adminTabcntl = (HtmlAnchor)PageHelper.FindControlRecursive(this, "adminTab");

                switch (CurrentUser.Role)
                {
                    case ChatForum.Business.Entity.RoleENUM.Administrator:
                        adminTabcntl.Style.Add("display", "block");
						postTab.Style.Add("display", "block");
						break;
					case ChatForum.Business.Entity.RoleENUM.Member:
                        postTab.Style.Add("display", "block");
						break;
                    case ChatForum.Business.Entity.RoleENUM.Guest:
                    default:
                        break;
                }
            }
            ShowError();
        }

        public void ShowError()
        {
            if (!string.IsNullOrWhiteSpace(Session["PageError"] + string.Empty))
            {
                errorDiv.Style.Add("display", "block");
                errorString.Text = Session["PageError"] + string.Empty;
            }
            Session["PageError"] = null;
        }
    }
}